package com.aurora.source.authority.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.aurora.source.R;
import com.aurora.source.authority.bean.AuthTypeDataBean;
import com.aurora.source.base.BaseRecyclerAdapter;
import com.aurora.source.base.CommonHolder;

import butterknife.BindView;

/**
 * @author: ww
 * @description:权限分类
 * @date: 2018/9/10
 */
public class AuthTypeAdapter extends BaseRecyclerAdapter<AuthTypeDataBean> {
    AuthTypeDataBean lastSelectData;
    @Override
    public CommonHolder<AuthTypeDataBean> setViewHolder(ViewGroup parent) {
        return new MyHolder(parent.getContext(), parent);
    }

     class MyHolder extends CommonHolder<AuthTypeDataBean> {

        @BindView(R.id.iv_mark)
        ImageView ivMark;
        @BindView(R.id.tv_type)
        TextView tvType;

        public MyHolder(Context context, ViewGroup root) {
            super(context, root, R.layout.item_auth_type);
        }

        @Override
        public void bindData(AuthTypeDataBean personAuthBean, int positon) {

            if(personAuthBean.isSelected()){
                ivMark.setVisibility(View.VISIBLE);
                tvType.setTextColor(Color.parseColor("#222222"));
                tvType.setBackgroundColor(Color.WHITE);
            }else {
                ivMark.setVisibility(View.GONE);
                tvType.setTextColor(Color.parseColor("#888888"));
                tvType.setBackgroundColor(Color.TRANSPARENT);
            }

            //点击事件，改变选择状态，把选择以后的数据传出去
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(lastSelectData==null){
                        lastSelectData = getData(getLayoutPosition());
                        lastSelectData.setSelected(true);
                    }else{
                        lastSelectData.setSelected(false);
                        lastSelectData = getData(getLayoutPosition());
                        lastSelectData.setSelected(true);
                    }
                    notifyDataSetChanged();
                    if(onItemClickListener!=null){
                        onItemClickListener.onClick(getLayoutPosition(),lastSelectData);
                    }
                }
            });

        }
    }
}